package com.lyshop.jinding.activitys;

import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.lyshop.jinding.R;
import com.lyshop.jinding.adapters.FollowViewpagerAdapter;
import com.lyshop.jinding.base.BaseActivity;

public class FollowListActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {
    private ViewPager vp_pager;
    private RadioGroup rg_group;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FollowViewpagerAdapter mPagerAdapter = new FollowViewpagerAdapter(getSupportFragmentManager());
        vp_pager.setAdapter(mPagerAdapter);
        vp_pager.setOffscreenPageLimit(2);
        vp_pager.setCurrentItem(0, false);
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_follow_list;
    }

    @Override
    protected void findViews() {
        rg_group = findViewById(R.id.rg_group);
        vp_pager = findViewById(R.id.vp_pager);
    }

    @Override
    protected void setListeners() {
        rg_group.setOnCheckedChangeListener(this);
        vp_pager.addOnPageChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_my_follow:
                vp_pager.setCurrentItem(0, true);
                break;
            case R.id.rb_follow_me:
                vp_pager.setCurrentItem(1, true);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        ((RadioButton) rg_group.getChildAt(position)).setChecked(true);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}